package com.zhupanlin.zhyl.common.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: 获取当前用户信息工具类
 * @date 2024/12/3 22:28
 */
public class AuthContextHolder {

    // 获取当前用户id
    public static Long getUserId(HttpServletRequest request) {
        // 从 header 中获取 token
        String token = request.getHeader("token");
        // jwt 从 token 获取 userid
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    // 获取当前用户名称
    public static String getUsername(HttpServletRequest request) {
        String token = request.getHeader("token");
        String userName = JwtHelper.getUserName(token);
        return userName;
    }

}
